package com.zian.controller.user;

import com.zian.common.R;
import com.zian.exception.BizIllegalException;
import com.zian.service.IPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Api(tags = "支付相关接口")
@RestController
@RequestMapping("/user/pay")
@RequiredArgsConstructor
public class PayController {

    private final IPayService payService;

    @PostMapping
    @ApiOperation("支付")
    public R<String> pay(@RequestParam("orderNo") String orderNo){
       String payInfo =  payService.pay(orderNo);
        return R.ok(payInfo);
    }

    @PostMapping("/notify")
    @ApiOperation("异步通知")
    public R<String>  payNotify(HttpServletRequest request){
        String out_trade_no = request.getParameter("out_trade_no");
        payService.payNotify(out_trade_no);
        return R.ok(out_trade_no);
    }



}
